<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 表单提交 -->
    <!-- 会将参数数据队列(user=a123123&pwd=123123) 提交到action所指的地址栏中   -->
    <!-- 以get方式 提交的数据 会拼接在地址栏 url之后 以 ? 分隔 -->
    <form onsubmit="return false">
        <div>
            <label for="user">用户名</label>
            <input class="user" type="text">
            <span class="user_span"></span>
        </div>
        <div>
            <label for="pwd">密码:</label>
            <input class="pwd" type="text">
            <span class="pwd_span"></span>
        </div>
        <div>
            <button id="logBtn">提交</button>
            <input type="reset">
        </div>
    </form>
</body>
<script>

    var logBtn = document.getElementById("logBtn");
    var userInp = document.querySelector(".user");
    var pwdInp = document.querySelector(".pwd");

    logBtn.onclick = function () {
        var user = userInp.value;
        var pwd = pwdInp.value;
        if (user && pwd) {

            var xhr = new XMLHttpRequest();

            // http://localhost/2101_php/day04/php/get.php?user=a123123&pwd=123123
            xhr.open("get", "../php/get.php?user=" + user + "&pwd=" + pwd, true);

            xhr.send();

            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    console.log(xhr.responseText);
                    var data = JSON.parse(xhr.responseText);
                    console.log(data);
                }
            }

        }
    }


</script>

</html>